<#setting classic_compatible="true">
<style type="text/css">
.channelcontent .item{
	margin:10px 20px;
}
.channelcontent .item .pic{
	max-height:150px;
	max-width:200px;
	margin-right:10px;
}
.imageuploadiframe{
	display:none;
}
.imageupload{
	display:none;
}
.imageupload label{
	display:block;
	margin:10px 20px;
}
.imageupload input{
	width:230px;
}
.imageupload button{
	margin:0px 20px;
}
</style>
<script type="text/javascript">
$(document).ready(function(e) {
	$('.simpleeditor').xheditor({tools:'simple'});
	$('.minieditor').xheditor({tools:'mini'});
	$('.fulleditor').xheditor({tools:'full'})
	dialog('.imageupload',{
		autoOpen:false,
		modal:true,
		resizable:false,
		title:'上传图片',
		width:400
	});
});
function channeloptionadd(){
	if(checkForm($('.channelcontent *[name]'))){
		$.ajax({
			url:'system/channelcontent!save.action',
			type:'POST',
			data:LC.serializeArray($('.channelcontent *[name]')),
			dataType:"JSON",
			success: function(rs){
				alert(rs.msg);
				if(rs.code=='1'){
					
					//goPage('system/channelOption.action?channelid='+'','.channeloption');
				}else{
					
				}
			}
		});
	}
}
var imgbtn;
function upimg(_this){
	imgbtn=_this;
	$('.imageupload').dialog('open')
}
function checkImageFile(){
	if(checkForm($('.imageupload *[name]'))){
		setTimeout(function(){
			$(window.frames["imageuploadiframe"].document).ready(function(e) {
				$( ".loading" ).dialog('close');
				var rs=$(window.frames["imageuploadiframe"].document).find('body').text()
				var data={};
				try{
					data= JSON.parse(rs);
				}catch(e){
					data=false;
				}
				if(data){
					if(data.code==1){
						/*alert('上传成功！')*/
						$(imgbtn).prev('img').attr('src',data.url);
						$(imgbtn).prev().prev().val(data.url);
						$('.imageupload').dialog('close')
					}else{
						alert(data.msg);
					}
				}else{
					alert('上传失败！');
				}
			});
		},500);
		$( ".loading" ).dialog('open');
		return true;
	}else{
		return false;
	}
}
</script>
<div class="channelcontent">
  <input type="hidden" name="id" isnull value="${channelcontent._id}" />
  <input type="hidden" name="channelid" value="${channelid}" />
  <#list channeloptions as mo>
  <#switch mo.type>
  	<#case "text">
    	<div class="item">${mo.description}：<input type="text" name="${mo.name}" value="${channelcontent[mo.name]}" /></div>
    <#break>
    <#case "textarea">
	    <div class="item">${mo.description}：<textarea name="${mo.name}">${channelcontent[mo.name]}</textarea></div>
    <#break>
    <#case "miniEditor">
    	<div class="item">${mo.description}：<textarea name="${mo.name}" class="minieditor">${channelcontent[mo.name]}</textarea></div>
    <#break>
    <#case "simpleEditor">
    	<div class="item">${mo.description}：<textarea name="${mo.name}" class="simpleeditor">${channelcontent[mo.name]}</textarea></div>
    <#break>
    <#case "fullEditor">
    	<div class="item">${mo.description}：<textarea name="${mo.name}" class="fulleditor">${channelcontent[mo.name]}</textarea></div>
    <#break>
    <#case "file">
    	<div class="item">
    	<input type="hidden" name="${mo.name}" value="${channelcontent[mo.name]}" />${mo.description}：<input type="text" name="${mo.name}" value="${channelcontent[mo.name]}" /></div>
    <#break>
    <#case "image">
    	<div class="item">
    	  <input type="hidden" name="${mo.name}" value="${channelcontent[mo.name]}" />${mo.description}：<img class="pic" src="${channelcontent[mo.name]!"/images/img_none.png"}" /><button type="button" onClick="upimg(this)">上传</button>
        </div>
    <#break>
    <#default>
    	<div class="item">${mo.description}：<input type="text" name="${mo.name}" value="${channelcontent[mo.name]}" /></div>
  </#switch>
  </#list>
  <div class="item"><button onClick="channeloptionadd()">保存</button></div>
</div>

<div>
  <iframe class="imageuploadiframe" src="" name="imageuploadiframe"></iframe>
  <div class="imageupload">
  <form action="image.action" target="imageuploadiframe" enctype="multipart/form-data" method="post" onSubmit="checkImageFile()">
    <label>文件：<input name="upfile" regx=".+\.(png)|(jpg)|(gif)" type="file" /></label>
    <label><button type="submit">上传</button><button type="reset">重置</button></label>
  </form>
  </div>
<div>